import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GuildUnionInviteGuildRenderer } from "./GuildUnionInviteGuildRenderer";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GuildUnionPosition } from "./rule/GuildUnionPosition";
import { PageTool } from "../../../../common/global/PageTool";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MsgManager } from "../../../manager/MsgManager";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class GuildUnionInviteListWindow
    
    export  class GuildUnionInviteListWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._tf = new GTextFormat(FontUtil.songtiName, 12, 16776960, null, null, null, null, null);
            this._scaleBgArr = [];
            this._textfieldArr = [];
            this._list = [];
            this.setSize(725, 365);
            this.titleHeight = 25;
            this.title = Language.getString(90236);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            return;
        }

        public set position(arg1: int)
        {
            this._position = arg1;
            return;
        }

        public get position(): int
        {
            return this._position;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            this._bg = ObjCreate.createBg(20, 40, 685, 276, this);
            this._scaleBgArr.push(this._bg);
            this._tileBg = ObjCreate.createBg(20, 38, 687, 35, this, ImagesConst.RbListHeader);
            this._scaleBgArr.push(this._tileBg);
            var loc1=0;
            while (loc1 < 5) 
            {
                this._scaleBgArr.push(ObjCreate.createBg(30, 110 + loc1 * 41, 665, 2, this, ImagesConst.SplitLine));
                ++loc1;
            }
            this._textfieldArr.push(ObjCreate.createGTextField(Language.getString(60862), 37, 46, 100, 20, this, this._tf));
            this._textfieldArr.push(ObjCreate.createGTextField(Language.getString(60863), 178, 46, 100, 20, this, this._tf));
            this._textfieldArr.push(ObjCreate.createGTextField(Language.getString(60864), 300, 46, 100, 20, this, this._tf));
            this._textfieldArr.push(ObjCreate.createGTextField(Language.getString(60865), 360, 46, 100, 20, this, this._tf));
            this._textfieldArr.push(ObjCreate.createGTextField(Language.getString(60866), 435, 46, 100, 20, this, this._tf));
            this._textfieldArr.push(ObjCreate.createGTextField(Language.getString(60867), 520, 46, 100, 20, this, this._tf));
            this._textfieldArr.push(ObjCreate.createGTextField(Language.getString(60868), 638, 46, 100, 20, this, this._tf));
            if (!this._guildList) 
            {
                this._guildList = ObjCreate.createTileList(20, 73, 690, 276, this);
                this._guildList.columnWidth = 687;
                this._guildList.rowHeight = 41;
                this._guildList.setStyle("cellRenderer", GuildUnionInviteGuildRenderer);
                this._guildListDp = new DataProvider([]);
            }
            this._guildList.dataProvider = this._guildListDp;
            this.addChild(this._guildList);
            ObjCreate.createGTextField(Language.getString(60885), 20, 328, 400, 20, this, GlobalStyle.textFormat5);
            this._pageSelec = ObjCreate.createPageSelecter(314, 328, this, PageSelecter.CompleteMode);
            this._pageSelec.maxPage = 5;
            this._pageSelec.configEventListener(flash.events.Event.CHANGE, this.onPageSelecChangeHandler);
            this._nameInput = ObjCreate.createGTextInput(490, 326, 110, 22, this);
            this._serchBtn = ObjCreate.createGButton(Language.getString(40367), this._nameInput.x + this._nameInput.width + 5, this._nameInput.y, 49, this._nameInput.height, this);
            this._serchBtn.configEventListener(flash.events.MouseEvent.CLICK, this.onSearchBtnClickHandler);
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            super.disposeImpl(arg1);
            while (this._scaleBgArr.length > 0) 
            {
                (this._scaleBgArr.pop() as ScaleBitmap).dispose();
            }
            this._bg = null;
            this._tileBg = null;
            while (this._textfieldArr.length > 0) 
            {
                (this._textfieldArr.pop() as GTextFiled).dispose();
            }
            if (this._guildList) 
            {
                this._guildListDp.removeAll();
                this._guildList.dataProvider = this._guildListDp;
            }
            if (this._pageSelec) 
            {
                this._pageSelec.dispose();
                this._pageSelec = null;
            }
            if (this._nameInput) 
            {
                this._nameInput.dispose();
                this._nameInput = null;
            }
            if (this._serchBtn) 
            {
                this._serchBtn.dispose();
                this._serchBtn = null;
            }
            return;
        }

        public updateGuildListDataprovider(arg1: Array<any>, arg2: int, arg3: int): void
        {
            if (this._position == GuildUnionPosition.GuildUnionPositionOne) 
            {
                return;
            }
            this._guildListDp.removeAll();
            this._guildListDp.addItems(arg1);
            this._guildList.dataProvider = this._guildListDp;
            this._pageSelec.currentPage = Math.ceil((arg2 + 1) / this._pageSize);
            this._pageSelec.maxPage = Math.ceil(arg3 / this._pageSize);
            return;
        }

        public updateInvitedListDataprovider(arg1: Array<any>): void
        {
            if (this._position == GuildUnionPosition.GuildUnionPositionOne) 
            {
                this._list = arg1;
                if (!this._pageTool) 
                {
                    this._pageTool = new PageTool(arg1, this._pageSize);
                }
                this._pageTool.array = arg1;
                this._pageSelec.maxPage = this._pageTool.pagesCount;
                this._guildListDp.removeAll();
                this._guildListDp.addItems(this._pageTool.getByPageNo(this._pageSelec.currentPage));
                this._guildList.dataProvider = this._guildListDp;
            }
            return;
        }

        /* internal  */onPageSelecChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._position != GuildUnionPosition.GuildUnionPositionOne) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildUnionGetGuildList, {"guildName":"", "startIndex":(this._pageSelec.currentPage - 1) * this._pageSize + 1}));
            }
            else 
            {
                this.updateInvitedListDataprovider(this._list);
            }
            return;
        }

        /* internal  */onSearchBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._position == GuildUnionPosition.GuildUnionPositionOne) 
            {
                MsgManager.showRollTipsMsg(Language.getString(60875));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildUnionGetGuildList, {"guildName": this._nameInput.text, "startIndex": 0}));
            }
            return;
        }

        /* internal */ /* var */_position: int;

        /* internal */ /* var */_pageSize: int=6;

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_tileBg: ScaleBitmap;

        /* internal */ /* var */_guildList: GTileList;

        /* internal */ /* var */_guildListDp: DataProvider;

        /* internal */ /* var */_pageSelec: PageSelecter;

        /* internal */ /* var */_nameInput: GTextInput;

        /* internal */ /* var */_serchBtn: GButton;

        /* internal */ /* var */_tf: GTextFormat;

        /* internal */ /* var */_scaleBgArr: Array<any>;

        /* internal */ /* var */_textfieldArr: Array<any>;

        /* internal */ /* var */_list: Array<any>;

        /* internal */ /* var */_pageTool: PageTool;
    }
